//
//  XTEncrypt+Base64.m
//  XTEncryptKit
//
//  Created by Tong on 2017/6/8.
//  Copyright © 2017年 Tong. All rights reserved.
//

#import "XTEncrypt+Base64.h"

@implementation XTEncrypt (Base64)


/**
 获取 Base64 加密的字符串
 
 @param sourceString 需要加密的字段
 @return 加密后的字符串
 */
+ (NSString *)getBase64EncodeStringFromString:(NSString *)sourceString
{
    if (!sourceString || [sourceString isEqual:[NSNull null]]) {
        return nil;
    }
    
    NSData *data = [sourceString dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
    NSString *result = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
    
    return result;
}


/**
 获取 Base64 解码字符串
 
 @param sourceString 需要解码的字段
 @return 解码后的字段
 */
+ (NSString *)getBase64DecodeStringFromString:(NSString *)sourceString
{
    if (!sourceString || [sourceString isEqual:[NSNull null]]) {
        return nil;
    }
    
    NSData *data = [[NSData alloc] initWithBase64EncodedString:sourceString options:NSDataBase64DecodingIgnoreUnknownCharacters];
    NSString *result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    
    return result;
}



@end

















